<?php

namespace Fuel\Migrations;

class Create_shows
{
	public function up()
	{
		\DBUtil::create_table('shows', array(
			'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
			'movie_id' => array('constraint' => 11, 'type' => 'smallint'),
			'auditorium_id' => array('constraint' => 11, 'type' => 'smallint'),
			'start_time' => array('type' => 'int'),
			'end_time' => array('type' => 'int'),
                        'movie_3d' => array('type' => 'tinyint'),
                        'language' => array('constraint' => 20, 'type' => 'varchar'),
			'price' => array('type' => 'decimal(5,2)')
		), array('id'));
/*                
1402056000, 1402063200
1402066800, 1402074000
1402142400, 1402149600
1402153200, 1402160400
1402246800, 1402254000
1402311600, 1402326000  - 3h, 5 movie
1402329600, 1402340400  - 3h
*/
                $all_shows = array(
                    array('movie_id' => 1, 'auditorium_id' => 2, 'start_time' => 1402056000, 'end_time' => 1402063200, 'movie_3d' => 0, 'language' => 'show_lv', 'price' => 4.99),
                    array('movie_id' => 2, 'auditorium_id' => 3, 'start_time' => 1402066800, 'end_time' => 1402074000, 'movie_3d' => 1, 'language' => 'show_lv', 'price' => 5.99),
                    array('movie_id' => 3, 'auditorium_id' => 4, 'start_time' => 1402142400, 'end_time' => 1402149600, 'movie_3d' => 0, 'language' => 'show_lv', 'price' => 7.00),
                    array('movie_id' => 4, 'auditorium_id' => 3, 'start_time' => 1402142400, 'end_time' => 1402149600, 'movie_3d' => 1, 'language' => 'show_lv', 'price' => 7.00),
                    array('movie_id' => 5, 'auditorium_id' => 2, 'start_time' => 1402311600, 'end_time' => 1402326000, 'movie_3d' => 0, 'language' => 'show_lv', 'price' => 7.50),
                    array('movie_id' => 6, 'auditorium_id' => 2, 'start_time' => 1402142400, 'end_time' => 1402149600, 'movie_3d' => 1, 'language' => 'show_lv', 'price' => 7.00),
                    array('movie_id' => 1, 'auditorium_id' => 3, 'start_time' => 1402329600, 'end_time' => 1402340400, 'movie_3d' => 0, 'language' => 'show_lv', 'price' => 7.00),
                    array('movie_id' => 2, 'auditorium_id' => 2, 'start_time' => 1402246800, 'end_time' => 1402254000, 'movie_3d' => 1, 'language' => 'show_lv', 'price' => 6.00),
                    array('movie_id' => 3, 'auditorium_id' => 2, 'start_time' => 1402142400, 'end_time' => 1402149600, 'movie_3d' => 0, 'language' => 'show_lv', 'price' => 6.50)
                );

                foreach($all_shows as $data) {
                    $show = \Model_Orm_Show::forge();
                    $show->movie_id = $data['movie_id'];
                    $show->auditorium_id = $data['auditorium_id'];
                    $show->start_time = $data['start_time'];
                    $show->end_time = $data['end_time'];
                    $show->movie_3d = $data['movie_3d'];
                    $show->language = $data['language'];
                    $show->price = $data['price'];
                    $show->save();
                }
	}

	public function down()
	{
		\DBUtil::drop_table('shows');
	}
}